package mysql

import "gorm.io/gorm"

type House struct {
	gorm.Model
	UserId      int64  `gorm:"type:int(20);not null;comment:用户id"`
	AreaId      int64  `gorm:"type:int(20);not null;comment:地区id"`
	Title       string `gorm:"type:varchar(20);not null;comment:标题"`
	Price       int64  `gorm:"type:int(20);not null;comment:价格"`
	Address     string `gorm:"type:varchar(20);not null;comment:地址"`
	RoomCount   int64  `gorm:"type:int(20);not null;comment:房源数"`
	Acreage     int64  `gorm:"type:int(20);not null;comment:面积"`
	Status      int64  `gorm:"type:tinyint(1);default:1;comment:状态:1:下架,2:上架"`
	CheckStatus int64  `gorm:"type:tinyint(1);default:1;comment:审核状态:1:待审核,2:审核通过,3:审核失败,"`
}

//设施表

type Facility struct {
	gorm.Model
	name string `gorm:"type:varchar(100),not null;comment:'设施名称'"`
}

// 房屋设施表

type HouseFacility struct {
	gorm.Model
	HouseId    int `gorm:"type:int;not null;index;comment:'房屋ID'"`
	FacilityId int `gorm:"type:int;not null;comment:'设施ID'"`
}

// 房屋图片

type HouseImage struct {
	gorm.Model
	HouseId int    `gorm:"type:int;not null;index;comment:'房屋ID'"`
	UrL     string `gorm:"type:varchar(255);not null;comment:'图片地址'"`
	Status  int    `gorm:"type:tinyint(1);default:1;comment:'状态:1:图片,2:视频'"`
}

// 修改审核状态
func (h *House) UpdateChecked() error {
	return Db.Model(&h).Where("id = ?", h.ID).Update("checked", h.CheckStatus).Error
}

// 修改房源状态
func (h *House) UpdateStatus() error {
	return Db.Model(&h).Where("id = ?", h.ID).Update("status", h.Status).Error
}

func (h *House) Create() error {
	return Db.Create(&h).Error
}

func (hf *HouseFacility) Create() error {
	return Db.Create(&hf).Error
}

func (hi *HouseImage) Create() error {
	return Db.Create(&hi).Error
}

//func (h *House)HomeList(keyword string)(homeList []*)  {
//
//}
